#### CSV files for web
load("post.uds.RData")
library(uds)
data(democracy1946.2008) # need to toggle based on version

# Zs
make.z.csv(post.uds, democracy$cowcode, thin=5, file="uds_1000.csv")
make.z.csv(post.uds, democracy$cowcode, thin=1, file="uds_5000.csv")
make.z.summary(post.uds, democracy$cowcode, thin=1, file="uds_summary.csv")

# vars
make.sigmasq.summary(post.uds, file="vars_summary.csv", thin=1)
make.sigmasq.csv(post.uds, file="vars_1000.csv", thin=5)
make.sigmasq.csv(post.uds, file="vars_5000.csv", thin=1)

# cuts
make.gamma.summary(post.uds, file="cuts_summary.csv", thin=1)
make.gamma.csv(post.uds, file="cuts_1000.csv", thin=5)
make.gamma.csv(post.uds, file="cuts_5000.csv", thin=1)

# perceptions

# trick for paper version for north vietname issue
# document out for 12-rater model
democracy <- rbind(democracy[1:1649,], democracy[1651:nrow(democracy),])

make.t.csv(post.uds, "arat", democracy, thin=5, file="arat_1000.csv")
make.t.csv(post.uds, "arat", democracy, thin=1, file="arat_5000.csv")
make.t.summary(post.uds, "arat", democracy, file="arat_summary.csv")

make.t.csv(post.uds, "blm", democracy, thin=5, file="blm_1000.csv")
make.t.csv(post.uds, "blm", democracy, thin=1, file="blm_5000.csv")
make.t.summary(post.uds, "blm", democracy, file="blm_summary.csv")

make.t.csv(post.uds, "bollen", democracy, thin=5, file="bollen_1000.csv")
make.t.csv(post.uds, "bollen", democracy, thin=1, file="bollen_5000.csv")
make.t.summary(post.uds, "bollen", democracy, file="bollen_summary.csv")

make.t.csv(post.uds, "freedomhouse", democracy, thin=5, file="freedomhouse_1000.csv")
make.t.csv(post.uds, "freedomhouse", democracy, thin=1, file="freedomhouse_5000.csv")
make.t.summary(post.uds, "freedomhouse", democracy, file="freedomhouse_summary.csv")

make.t.csv(post.uds, "hadenius", democracy, thin=5, file="hadenius_1000.csv")
make.t.csv(post.uds, "hadenius", democracy, thin=1, file="hadenius_5000.csv")
make.t.summary(post.uds, "hadenius", democracy, file="hadenius_summary.csv")

make.t.csv(post.uds, "mainwaring", democracy, thin=5, file="mainwaring_1000.csv")
make.t.csv(post.uds, "mainwaring", democracy, thin=1, file="mainwaring_5000.csv")
make.t.summary(post.uds, "mainwaring", democracy, file="mainwaring_summary.csv")

make.t.csv(post.uds, "munck", democracy, thin=5, file="munck_1000.csv")
make.t.csv(post.uds, "munck", democracy, thin=1, file="munck_5000.csv")
make.t.summary(post.uds, "munck", democracy, file="munck_summary.csv")

make.t.csv(post.uds, "pacl", democracy, thin=5, file="pacl_1000.csv")
make.t.csv(post.uds, "pacl", democracy, thin=1, file="pacl_5000.csv")
make.t.summary(post.uds, "pacl", democracy, file="pacl_summary.csv")

make.t.csv(post.uds, "polity", democracy, thin=5, file="polity_1000.csv")
make.t.csv(post.uds, "polity", democracy, thin=1, file="polity_5000.csv")
make.t.summary(post.uds, "polity", democracy, file="polity_summary.csv")

make.t.csv(post.uds, "polyarchy", democracy, thin=5, file="polyarchy_1000.csv")
make.t.csv(post.uds, "polyarchy", democracy, thin=1, file="polyarchy_5000.csv")
make.t.summary(post.uds, "polyarchy", democracy, file="polyarchy_summary.csv")

make.t.csv(post.uds, "prc", democracy, thin=5, file="prc_1000.csv")
make.t.csv(post.uds, "prc", democracy, thin=1, file="prc_5000.csv")
make.t.summary(post.uds, "prc", democracy, file="prc_summary.csv")

make.t.csv(post.uds, "vanhanen", democracy, thin=5, file="vanhanen_1000.csv")
make.t.csv(post.uds, "vanhanen", democracy, thin=1, file="vanhanen_5000.csv")
make.t.summary(post.uds, "vanhanen", democracy, file="vanhanen_summary.csv")
